package com.caiden_micheal.user.mapper;

import com.caiden_micheal.org.domain.Org;
import com.caiden_micheal.org.domain.OrgAuthority;
import com.caiden_micheal.permission.domain.Permission;
import com.caiden_micheal.user.domain.UserAuthority;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrgAuthorityMapper {
    List<UserAuthority> findOrgAuthorityListById(@Param("id") Long id);

    void updateByOrgId(@Param("orgAuthority") OrgAuthority orgAuthority);

    void updateByAuthorityId(@Param("orgAuthority") OrgAuthority orgAuthority);

    @Select("SELECT org_id FROM sys_org_authority WHERE authority_id=#{permissionId}")
    List<Long> findOrgIdsByAuthorityId(@Param("permissionId") Long permissionId);

    @Delete("DELETE FROM sys_org_authority WHERE org_id=#{orgId} AND authority_id=#{permissionId}")
    void deleteAuthority(@Param("orgId") Long orgId, @Param("permissionId") Long permissionId);

    @Select("SELECT authority_id FROM sys_org_authority WHERE org_id=#{orgId}")
    List<Long> findAuthorityIdsByOrgId(@Param("orgId") Long orgId);

    void batchAddByAuthorityListAndPosition(@Param("authorityList") List<Permission> permissionList, @Param("org") Org org);

    List<Long> findAuthorityIdsByOrgIds(@Param("orgIdList") List<Long> orgIdList);

    List<UserAuthority> findAuthoritysByOrgIds(@Param("orgIdList") List<Long> orgIdList);

    @Delete("DELETE FROM sys_org_authority WHERE authority_id=#{permissionId}")
    void removeByPermissionId(@Param("permissionId") Long permissionId);
}
